import { Login, ResDetail } from "@/api/interface";
// import { DictState } from "@/stores/interface";
import { PORT1 } from "@/api/config/servicePort";
// import authMenuList from "@/assets/json/authMenuList.json";
// import authButtonList from "@/assets/json/authButtonList.json";
import http from "@/api";
import qs from "qs";

/**
 * @name 登录模块
 */
// 用户登录
export const loginApi = (params: Login.ReqLoginForm) => {
  return http.post<Login.ResLogin>(PORT1 + `/Login/GetJwtToken`, params, { noLoading: true }); // 正常 post json 请求  ==>  application/json
  // return http.post<Login.ResLogin>(PORT1 + `/login`, params, { noLoading: true }); // 控制当前请求不显示 loading
  // return http.post<Login.ResLogin>(PORT1 + `/login`, {}, { params }); // post 请求携带 query 参数  ==>  ?username=admin&password=123456
  // return http.post<Login.ResLogin>(PORT1 + `/login`, qs.stringify(params)); // post 请求携带表单参数  ==>  application/x-www-form-urlencoded
  // return http.get<Login.ResLogin>(PORT1 + `/login?${qs.stringify(params, { arrayFormat: "repeat" })}`); // get 请求可以携带数组等复杂参数
};
// 获取行业列表
export const getIndustryList = (params: {}) => {
  return http.post<Login.ResIndustryList>(PORT1 + `/CoreCmsIndustry/GetPageList`, qs.stringify(params));
};

export const getStoreTypeListAPI = (params: {}) => {
  return http.post<ResDetail<Login.StoreTypeList[]>>(PORT1 + `/corecmsstore/GetStoreTypeList`, qs.stringify(params));
};

// 注册门店账号
export const registerStore = (params: {}) => {
  return http.post<Login.ResIndustryList>(PORT1 + `/CoreCmsStore/DoCreate`, params);
};

// 获取动态验证码
export const getIdentify = () => {
  return http.post(PORT1 + `/Login/GetIdentify`);
};

// 发送验证码
export const sendVeriCode = (params: {}) => {
  return http.post<ResPageLogin.ResIndustryList>(PORT1 + `/Login/SendVeriCode`, qs.stringify(params));
};

// 获取菜单列表
export const getAuthMenuListApi = (params: {}) => {
  return http.post<Menu.MenuOptions[]>(PORT1 + `/SysMenuPage/GetPageList`, qs.stringify(params), { noLoading: true });
  // 如果想让菜单变为本地数据，注释上一行代码，并引入本地 authMenuList.json 数据
  // return authMenuList;
};

// 获取数字字典数据
// export const getDictApi = () => {
//   return http.post<DictState>(PORT1 + `/dict`, {}, { noLoading: true });
// };

// 获取按钮权限
export const getAuthButtonListApi = () => {
  return http.post<Login.ResAuthButtons>(PORT1 + `/SysMenuPageDict/GetPageList`, {}, { noLoading: true });
  // 如果想让按钮权限变为本地数据，注释上一行代码，并引入本地 authButtonList.json 数据
  // return authButtonList;
};

// 用户退出登录
export const logoutApi = () => {
  return http.post(PORT1 + `/logout`);
};
